/// <license>
/// Copyright (c) 2002-2008, DotNetNuke Corporation
/// All rights reserved
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
/// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
/// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
/// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
/// of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
/// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
/// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
/// DEALINGS IN THE SOFTWARE.
/// </license>

#region Using Statements

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Permissions;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Modules.NavigationProvider;
using DotNetNuke.UI.WebControls;

using DotNetNuke.ModuleToolkit.Common;
using DotNetNuke.ModuleToolkit.Modules.Skinning;

#endregion

namespace DotNetNuke.ModuleToolkit.Modules.Skinning.SkinObjects
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The Help skin object displays Help
    /// </summary>
    /// <history>
    /// 	[cnurse]	08/04/2006	created
    /// </history>
    /// -----------------------------------------------------------------------------
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
    ToolboxData("<{0}:Help runat=\"server\"> </{0}:Help>")]
    public class Help : ModuleSkinObjectBase
    {
        #region Private Members

        private string _HelpKey;
        private string _HelpText;

        #endregion

        #region Protected Properties

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Default Css Class
        /// </summary>
        /// <history>
        ///     [cnurse]  08/04/2006  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(false)]
        protected override String DefaultCssClass
        {
            get { return "Help"; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets the design time text to display
        /// </summary>
        /// <history>
        ///     [cnurse]  08/04/2006  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(false)]
        protected override string DesignTimeText
        {
            get { return Constants.TEXT_Help; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets the text to display
        /// </summary>
        /// <history>
        ///     [cnurse]  08/04/2006  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(false)]
        protected override string DisplayText
        {
            get
            {
                string helpText = this.DesignTimeText;

                if (!DesignMode)
                {
                    if (String.IsNullOrEmpty(HelpKey) || DesignMode)
                        helpText = HelpText;
                    else
                        helpText = LocalizeString(HelpKey);
                }

                //Fix images
                string folder = this.ParentControl.TemplateSourceDirectory;
                helpText = helpText.Replace("<img src=\"", "<img src=\"" + folder + "/");
                return helpText;
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// A String that contains the localization resource key for the Help Text
        /// </summary>
        /// <history>
        /// 	[cnurse]	08/04/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(true),
        Category("Localization"),
        DefaultValue(""),
        Description("The Resource Key to use to localize the Help Text")]
        public string HelpKey
        {
            get { return _HelpKey; }
            set { _HelpKey = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The text of the control in View Mode
        /// </summary>
        /// <history>
        /// 	[cnurse]	04/12/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(true),
        Category("Appearance"),
        DefaultValue(""),
        Description("The Help Text.")]
        public string HelpText
        {
            get { return _HelpText; }
            set { _HelpText = value; }
        }

        #endregion

        #region Protected Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// AddAttributesToRender adds attributes to the control
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="writer">An HtmlTextWriter</param>
        /// <history>
        /// 	[cnurse]	03/18/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            //Make sure the CssClass is set to the default for the control
            if (CssClass == String.Empty) CssClass = DefaultCssClass;

            //Render the style
            ControlStyle.AddAttributesToRender(writer);

            //Call the base control's method
            base.AddAttributesToRender(writer);
        }

        #endregion

    }
}
